using System;
using System.Collections.Generic;
using ProtoModels;
using UnityEngine;

public class MatchParameters : MonoBehaviour
{
	public class MatchParams
	{
		public struct ShoeParams
		{
			public FloatRange moveSpeed;

			public FloatRange jumpSpeed;

			public int shotsToMinSpeed;

			public float normalizedVisualSpeed;

			public string shoesId;
		}

		[Serializable]
		public class PlayerEquipmentOverride
		{
			public bool shouldUseOverride;

			public string storeItemName;

			public StoreItemsConfig.StoreItem storeItem
			{
				get
				{
					return StoreItemsConfig.instance.FindItemForName(storeItemName);
				}
				set
				{
					if (value == null)
					{
						storeItemName = string.Empty;
					}
					else
					{
						storeItemName = value.name;
					}
				}
			}

			public PlayerEquipmentOverride()
			{
				shouldUseOverride = false;
				storeItem = null;
			}

			public PlayerEquipmentOverride(StoreItemsConfig.StoreItem storeItem)
			{
				shouldUseOverride = true;
				this.storeItem = storeItem;
			}
		}

		public struct MultiplayerParams
		{
			public string arenaName;

			public string opponentName;

			public int opponentFlag;

			public int activeTag;

			public float eloRank;

			public int multiplayerWins;

			public int multiplayerLoses;

			public bool multiplayerLosesKnown;

			public MultiplayerRoomType roomType;

			public int opponentLevel;

			public int opponentCoins;

			public int multiplayerVersion;

			public MIntro intro;

			public string supportRoomNameGUID;

			public string racketId;

			public ShoeParams remoteShoe;

			public int remoteLookGender;

			public List<CharacterLookProperty> remoteLooks;

			public RemoteStats remoteSkills;

			public bool useRoomParams;

			public string player1Pid;

			public string player2Pid;

			public string opponentImageUrl;

			public bool isRematch;
		}

		public MatchEventsDelegate eventsDelegate;

		public MatchType matchType;

		public MultiplayerParams multiplayerParams;

		public int initPlayerTag;

		public int player1Flag = GGPlayerSettings.instance.Model.flag;

		public int player2Flag;

		public string player1Name = GGPlayerSettings.instance.GetName();

		public string player2Name = "Opponent";

		public PlayerType p1Type = PlayerType.avatar;

		public PlayerType p2Type = PlayerType.avatar;

		public int ballsAvailable = 1;

		public int EloRatingK;

		public int roomLook = 4;

		public SeasonDefinitions.SeasonEvent seasonEvent;

		public AiPlayerDefinition aiDefinition;

		public PlayerCareerStageDefinition.GameParameters gameParams;

		public string arenaName;

		public int pointsToWinGame = 11;

		public int gamesToWinMatch = 30;

		public int coinsToWin;

		public float skillPointsScale = 1f;

		public float skillPointsOffset;

		public float influenceOfEquipment = 1f;

		public FloatRange maxSkillPointsDifference = new FloatRange
		{
			min = -1000f,
			max = 1000f
		};

		public TableTennisHitTargets.HitTargetsDefinition hitTargetsDefinition;

		public PlayerDB.TournamentPlayer opponentDefinition;

		public GameDoneListener gameDoneListener;

		public PlayerEquipmentOverride shoeOverride = new PlayerEquipmentOverride();

		public PlayerEquipmentOverride racketOverride = new PlayerEquipmentOverride();

		public bool overrideLoop;

		public LoopParams loopParams;

		public static MatchParams CreateDefault()
		{
			MatchParams matchParams = new MatchParams();
			matchParams.matchType = MatchType.SinglePlayer;
			GGPlayerSettings instance = GGPlayerSettings.instance;
			matchParams.player1Name = instance.GetName();
			matchParams.player1Flag = instance.Model.flag;
			matchParams.p1Type = PlayerType.avatar;
			matchParams.p2Type = PlayerType.avatar;
			matchParams.shoeOverride = new PlayerEquipmentOverride();
			matchParams.racketOverride = new PlayerEquipmentOverride();
			return matchParams;
		}

		public static MatchParams CreateTutorialParams()
		{
			MatchParams matchParams = CreateDefault();
			matchParams.matchType = MatchType.Tutorial;
			matchParams.p1Type = PlayerType.avatar;
			matchParams.p2Type = PlayerType.avatar;
			return matchParams;
		}

		public void SetMultiplayer(MultiplayerParams mp, MultiplayerRooms.RoomInfo room)
		{
			player2Name = mp.opponentName;
			p1Type = PlayerType.avatar;
			player2Flag = mp.opponentFlag;
			p2Type = PlayerType.avatar;
			initPlayerTag = mp.activeTag;
			arenaName = mp.arenaName;
			skillPointsScale = ConfigBase.instance.multiplayerSkillPointsScale;
			skillPointsOffset = ConfigBase.instance.multiplayerSkillPointsOffset;
			player1Name = BehaviourSingletonInit<FriendProfilesManager>.instance.PlayerName;
			EloRatingK = ((room != null) ? room.EloRatingK : 0);
			multiplayerParams = mp;
			matchType = MatchType.MultiPlayer;
			if (room != null)
			{
				skillPointsScale = room.influenceOfSkill;
				skillPointsOffset = room.skillOffset;
				influenceOfEquipment = room.inflounceOfEquipment;
				arenaName = room.arenaName;
			}
			gamesToWinMatch = 1;
		}
	}

	private static MatchParams _matchParams;

	public static MatchParams InitParameters
	{
		get
		{
			if (_matchParams == null)
			{
				_matchParams = new MatchParams();
			}
			return _matchParams;
		}
		set
		{
			_matchParams = value;
		}
	}

	public static void ResetInitParameters()
	{
		InitParameters = MatchParams.CreateDefault();
	}
}
